<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Other extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->checkAdmin($this->session->userdata('admin_id'));
        $this->data['controller'] = 'other';         
        $this->load->model('Mother');
    }
    
    public function notification()
    {
        $this->data['data'] = $this->Mother->getInfoNotification();
        
        $this->load->library('form_validation');
        $this->form_validation->set_rules('content', 'Nội dung', 'required');
        $this->form_validation->set_rules('hotline', 'Hotline', 'required');
        if($this->form_validation->run() === TRUE)
        {
            $this->Mother->addInfoNotification();
            die('<meta charset="utf-8"><script>alert("Cập nhật thành công");window.location.href="'.$this->data['baseurl'].'manage/notification.html";</script>');
        }
        $this->data['action'] = 'notification';
        $this->load->view('temp/layout', $this->data);
    }
    
    public function contentright()
    {
        $this->data['data'] = $this->Mother->getInfoContentRight();
        
        $this->load->library('form_validation');
        $this->form_validation->set_rules('content', 'Nội dung', 'required');
        if($this->form_validation->run() === TRUE)
        {
            $this->Mother->addContentRight();
            die('<meta charset="utf-8"><script>alert("Cập nhật thành công");window.location.href="'.$this->data['baseurl'].'manage/content-right.html";</script>');
        }
        $this->data['action'] = 'contentright';
        $this->load->view('temp/layout', $this->data);
    }
    
    public function addcontentright()
    {
        $this->load->library('form_validation');
        $this->form_validation->set_rules('content', 'Nội dung', 'required');
        if($this->form_validation->run() === TRUE)
        {
            $this->Mother->addContentRight();
            die('<meta charset="utf-8"><script>alert("Thêm thành công");window.location.href="'.$this->data['baseurl'].'manage/content-right.html";</script>');
        }
        $this->data['action'] = 'addcontentright';
        $this->load->view('temp/layout', $this->data);
    }
    
    public function editcontentright()
    {
        $this->data['id'] = $this->getParamInt('id');
        $this->load->library('form_validation');
        $this->form_validation->set_rules('content', 'Nội dung', 'required');
        $this->data['data'] = $this->Mother->getCright($this->data['id']);
        if($this->form_validation->run() === TRUE)
        {
            $this->Mother->editContentRight($this->data['id']);
            die('<meta charset="utf-8"><script>alert("Cập nhật thành công");window.location.href="'.$this->data['baseurl'].'manage/content-right.html";</script>');
        }
        $this->data['action'] = 'editcontentright';
        $this->load->view('temp/layout', $this->data);
    }
    
    public function deletecontentright()
    {
        $id = $this->getParamInt('id');
        $this->Mother->deleteCright($id);
        die('<meta charset="utf-8"><script>alert("Xóa thành công");window.location.href="'.$this->data['baseurl'].'manage/content-right.html";</script>');
    }
    
    public function savesortcontentright()
    {
        $id_list = $this->getParamArray('id');
        $this->Mother->sortsaveDB($id_list);
    }
    
    public function introindex()
    {
        $this->data['data'] = $this->Mother->getInfoIntroIndex();
        
        $this->load->library('form_validation');
        $this->form_validation->set_rules('content', 'Chúng tôi cam kết', 'required');
        $this->form_validation->set_rules('content2', 'Sản phẩm của chúng tôi', 'required');
        if($this->form_validation->run() === TRUE)
        {
            $this->Mother->addIntroIndex();
            die('<meta charset="utf-8"><script>alert("Cập nhật thành công");window.location.href="'.$this->data['baseurl'].'manage/intro-home.html";</script>');
        }
        $this->data['action'] = 'introindex';
        $this->load->view('temp/layout', $this->data);
    }
    
    public function nvship()
    {
        $this->data['data'] = $this->Mother->getInfoship();
        
        $this->load->library('form_validation');
        $this->form_validation->set_rules('content', 'Nội dung', 'required');
        if($this->form_validation->run() === TRUE)
        {
            $this->Mother->addship();
            die('<meta charset="utf-8"><script>alert("Cập nhật thành công");window.location.href="'.$this->data['baseurl'].'manage/html-ship.html";</script>');
        }
        $this->data['action'] = 'nvship';
        $this->load->view('temp/layout', $this->data);
    }
    
    public function footer()
    {
        $this->data['data'] = $this->Mother->getInfofooter();
        
        $this->load->library('form_validation');
        $this->form_validation->set_rules('content', 'Nội dung', 'required');
        if($this->form_validation->run() === TRUE)
        {
            $this->Mother->addfooter();
            die('<meta charset="utf-8"><script>alert("Cập nhật thành công");window.location.href="'.$this->data['baseurl'].'manage/content-footer.html";</script>');
        }
        $this->data['action'] = 'footer';
        $this->load->view('temp/layout', $this->data);
    }
    
    public function intro()
    {
        $this->data['data'] = $this->Mother->getintro();
        
        $this->load->library('form_validation');
        $this->form_validation->set_rules('content', 'Nội dung', 'required');
        $this->form_validation->set_rules('title', 'Tiêu đề', 'required');
        if($this->form_validation->run() === TRUE)
        {
            $dataimage = $this->getParamString('img_hidden');
            if(!in_array($dataimage, array(null, '', '0')))
            {
                $timenow = time().rand(0,9999);
                $nameimagess = 'nhatnv-'.$timenow.'.png';
                $paths = PROJECT_PATH.'/public/upload/images/';
                $exp = explode("[removed]",$dataimage);
                $this->savefile($exp[1],$paths,$nameimagess);
                $img = 'public/upload/images/'.$nameimagess;
            }else{
                $img = '';
            }
            $this->Mother->addintro($img);
            die('<meta charset="utf-8"><script>alert("Cập nhật thành công");window.location.href="'.$this->data['baseurl'].'manage/content-intro.html";</script>');
        }
        $this->data['action'] = 'intro';
        $this->load->view('temp/layout', $this->data);
    }
    
    public function savesorttopichot()
    {
        $id_list = $this->getParamArray('id');
        $this->Mother->sortsaveTopicDB($id_list);
    }
    
    public function topichot()
    {
        $this->data['data'] = $this->Mother->getTopicHot();
        $this->data['action'] = 'topichot';
        $this->load->view('temp/layout', $this->data);
    }
    
    
    public function edittopichot()
    {
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->form_validation->set_rules('nameTopic', 'Tên topic', 'required');
        $this->form_validation->set_rules('link_all', 'Link bài viết', 'required');
        
        $this->data['id'] = $this->getParamInt('id');
        $this->data['data'] = $this->Mother->getTopicID($this->data['id']);
        $this->data['typelink'] = $this->Mother->getLink($this->data['data']->id_content);
        
        if($this->form_validation->run() === TRUE)
        {
        
            $run = $this->Mother->editTopicDb($this->data['id']);
            if($run == 200)
            {
                die('<meta charset="utf-8"><script>alert("Sửa Topic Hot thành công");window.location.href="'.$this->data['baseurl'].'manage/topichot.html";</script>');
            }
        }
        $this->data['action'] = 'edittopichot';
        $this->load->view('temp/layout', $this->data);
    }
    
    
    /**
     * 
     * Support
     * 
     */
     
     public function savesortsupport()
    {
        $id_list = $this->getParamArray('id');
        $this->Mother->sortsaveSupportDB($id_list);
    }
    
    public function support()
    {
        $this->data['data'] = $this->Mother->getsupportHot();
        $this->data['action'] = 'support';
        $this->load->view('temp/layout', $this->data);
    }
    
    
    public function editsupport()
    {
        $this->load->helper('form');
        $this->load->library('form_validation');$this->form_validation->set_rules('content', 'Tên tài khoản yahoo hoặc skype hoặc số điện thoại', 'required');
        
        $this->data['id'] = $this->getParamInt('id');
        $this->data['data'] = $this->Mother->getsupportHotID($this->data['id']);
        $this->data['selectTypeSupport'] = $this->Mother->selectTypeSupport($this->data['data']->type_c);
        
        if($this->form_validation->run() === TRUE)
        {
        
            $run = $this->Mother->editsupportDb($this->data['id']);
            if($run == 200)
            {
                die('<meta charset="utf-8"><script>alert("Sửa Hỗ trợ trực tuyến thành công");window.location.href="'.$this->data['baseurl'].'manage/support.html";</script>');
            }
        }
        $this->data['action'] = 'editsupport';
        $this->load->view('temp/layout', $this->data);
    }
    
    public function addsupport()
    {
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->form_validation->set_rules('content', 'Tên tài khoản yahoo hoặc skype hoặc số điện thoại', 'required');
        $this->data['selectTypeSupport'] = $this->Mother->selectTypeSupport('');
        if($this->form_validation->run() === TRUE)
        {
        
            $run = $this->Mother->addsupportDb();
            if($run == 200)
            {
                die('<meta charset="utf-8"><script>alert("Thêm Hỗ trợ trực tuyến thành công");window.location.href="'.$this->data['baseurl'].'manage/support.html";</script>');
            }
        }
        $this->data['action'] = 'addsupport';
        $this->load->view('temp/layout', $this->data);
    }
    
    public function deletesupport()
    {
        $id = $this->getParamInt('id');
        $this->Mother->deletesupportdb($id);
        die('<meta charset="utf-8"><script>alert("Xóa thành công");window.location.href="'.$this->data['baseurl'].'manage/support.html";</script>');
    }
}
